#List of Template files
OUTPUTLOC = /var/www/output
OUTPUTS = $(OUTPUTLOC)/test.txt $(OUTPUTLOC)/latextest.pdf $(OUTPUTLOC)/htmltest.html $(OUTPUTLOC)/cv.txt
PUBLISHLOC = /var/www/published
QUERY_HANDLER = bin/FileExtender.pl

REMOTE = yes
FLAGS = -i Group.pem
CONNECTION = ubuntu@ec2-50-19-188-160.compute-1.amazonaws.com

DB = dbi:mysql:DrDocSmall:drdoc2.cfcbem1draxy.us-east-1.rds.amazonaws.com:3306
UNAME = DrDocRoot
PW = DrDoc5m4ll

all : $(OUTPUTS)

$(OUTPUTLOC)/%.pdf : temp/%.tex
	pdflatex -output-directory temp $^
	mv $(patsubst %.tex, %.pdf, $^) $@

temp/%.tex : templates/%.tex
	perl $(QUERY_HANDLER) -s $(DB) -i $^ -o $@ -u $(UNAME) -p $(PW)

$(OUTPUTLOC)/% : templates/%
	perl $(QUERY_HANDLER) -s $(DB) -i $^ -o $@ -u $(UNAME) -p $(PW)
	
publish : $(OUTPUTS)
ifeq ($(REMOTE),yes)
	-sudo -u ubuntu scp $(FLAGS) $^ $(CONNECTION):$(PUBLISHLOC)
else
	-mv $^ $(PUBLISHLOC)
endif

clean :
	-rm $(OUTPUTLOC)/*
	-rm temp/*

unpublish :
	rm $(PUBLISHLOC)/*
